const { fnm, fnm_s } = require('../test-utils');
const { Compilation } = require('webpack');

// // @deprecated
// compilation.hooks.additionalChunkAssets.tap(name, (chunks) => {
//   console.log("------------- additionalChunkAssets");
//   // 使用 processAssets + stage 为 Compilation.PROCESS_ASSETS_STAGE_*
// });

// // @deprecated
// compilation.hooks.optimizeChunkAssets.tapAsync(
//   name,
//   (chunks, callback) => {
//     console.log("------------- optimizeChunkAssets");
//     callback();
//     // 使用 processAssets + Compilation.PROCESS_ASSETS_STAGE_*
//   }
// );

// // @deprecated
// compilation.hooks.afterOptimizeChunkAssets.tap(name, (chunks) => {
//   console.log("------------- afterOptimizeChunkAssets");
//   // 使用 processAssets + Compilation.PROCESS_ASSETS_STAGE_*
// });

/**
 *
 * @param {import('webpack').Compilation} compilation
 */
module.exports = function (compilation) {
  const name = '个人测试 TestCompilationPlugin';
  compilation.hooks.beforeModuleAssets.tap(name, () => {
    console.log('------------- beforeModuleAssets');
  });
  compilation.hooks.shouldGenerateChunkAssets.tap(name, () => {
    console.log('------------- shouldGenerateChunkAssets');
    // return true;
  });
  compilation.hooks.beforeChunkAssets.tap(name, () => {
    console.log('------------- beforeChunkAssets');
  });

  compilation.hooks.optimizeAssets.tapAsync(name, (assets, callback) => {
    console.log('------------- optimizeAssets');
    callback();
  });

  compilation.hooks.afterOptimizeAssets.tap(name, (assets) => {
    console.log('------------- afterOptimizeAssets');
  });
  compilation.hooks.processAssets.tapAsync(
    {
      name,
      stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
    },
    (assets, callback) => {
      console.log('------------- processAssets');
      //   参考：https://webpack.js.org/api/compilation-hooks/#processassets
      callback();
    }
  );
  compilation.hooks.afterProcessAssets.tap(name, (assets) => {
    console.log('------------- afterProcessAssets');
  });

  compilation.hooks.moduleAsset.tap(name, (module, filename) => {
    console.log('------------- moduleAsset');
  });
  // compilation.hooks.chunkAsset.tap(name, (chunk, filename) => {
  //   console.log("------------- chunkAsset");
  // });
  // compilation.hooks.assetPath.tap(name, (path, options) => {
  //   console.log("------------- assetPath",path,options);
  // });
};
